package com.student.work.controller;

import com.student.work.common.BaseResponse;
import com.student.work.model.UserProfile;
import com.student.work.model.UserRegisterInfo;
import com.student.work.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @date 2020/2/19 20:56
 */
@Controller
@RequestMapping("/work")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 注册
     */
    @PostMapping("/signUp")
    @ResponseBody
    public BaseResponse<Map<String, Object>> signUp(@RequestBody UserRegisterInfo info) {
        return userService.signUp(info);
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    @ResponseBody
    public BaseResponse<Map<String, Object>> login(@RequestBody UserRegisterInfo info) {
        return userService.login(info);
    }

    /**
     * 创建用户画像
     */
    @PostMapping("/createProfile")
    @ResponseBody
    public BaseResponse<Map<String, Object>> createProfile(@RequestBody UserProfile profile) {
        return userService.createProfile(profile);
    }

    /**
     * 获取用户画像
     */
    @GetMapping("/getProfile")
    @ResponseBody
    public BaseResponse<UserProfile> getProfile(@RequestParam("userId") Long userId) {
        return userService.getProfile(userId);
    }

    /**
     * 用户列表
     */
    @GetMapping("/userList")
    @ResponseBody
    public BaseResponse<Map<String, Object>> userList(@RequestParam("pageNum") int pageNum,
                                                      @RequestParam("pageSize") int pageSize) {
        return userService.userList(pageNum, pageSize);
    }

    /**
     * 注册
     */
    @PostMapping("/deleteUser")
    @ResponseBody
    public BaseResponse<Map<String, Object>> deleteUser(@RequestBody UserRegisterInfo info) {
        return userService.deleteUser(info);
    }
}
